var example = new Vue({
  el: '#example',
  data: {
		token:"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyaWQiOiJsaXV5YW5nIiwidXNlclB3ZCI6IjEyMzQ1NiIsInVzZXJOYW1lIjoiQWRtaW4iLCJVSWQiOiI2ZTJjNDQ5YS05Y2UxLTQxMmItYmFjOC1mZjdjMzY5ODE0ZTAifQ.-_GYkZe9zumBZxUfpRXV6-ojYgw6Zw1L4uwWLD1myJk",
		requestpath:"http://192.168.1.109/JZXY.EMP.AppSystem",
		mons_all:[],
		mons_all_search:[],
		mons_sele:[],
		key_left:"",
		key_right:"",
		isloading:true,
		IsSence:false,
		SampingCode:"",
  },
  mounted:function(){
			this.SamplingTypeleft = this.SamplingTypeall_t
  },
  methods: {
	  	gtouchstart:function(item){
	  	  timeOutEvent = setTimeout(function(){
	  		  console.log(item)
	  	  },300);
	  		return false;
	  	  },
	  	gtouchend:function(item){
	  	  clearTimeout(timeOutEvent);
	  	},
		GetProjectDetail(projectid){
			return axios.get(this.requestpath+'/api/Project/GetProjectDetail',{
						params:{
							proid:projectid
						},
						headers:{token:this.token}
					})
		},
		LoadTag(projectid){
			return axios.get(this.requestpath+'/api/Project/LoadTag',{
						params:{
							ProjectId:projectid
						},
						headers:{token:this.token}
					})
		},
		LoadMethod(tag){
			return axios.get(this.requestpath+'/api/Project/LoadMethod',{
						params:{
							tag:tag
						},
						headers:{token:this.token}
					})
		},
		GetSampDetail(sampId,flowId,isCheck){
			return axios.get(this.requestpath+'/api/Project/GetSampDetail',{
						params:{
							sampId: sampId,
							flowId:flowId,
							isCheck: isCheck
						},
						headers:{token:this.token}
					})
		},
		GetPlanUsers(projectid){
			return axios.get(this.requestpath+'/api/Project/GetPlanUsers',{
						params:{
							projectId:projectid
						},
						headers:{token:this.token}
					})
		},
		GetUsersbyCode(rightCode){
			return axios.get(this.requestpath+'/api/Project/GetUserByCode',{
						params:{
							rightCode:rightCode
						},
						headers:{token:this.token}
					})
		},
		GetunitAll(){
			return axios.get(this.requestpath+'/api/Common/GetAll',{
						params:{
						},
						headers:{token:this.token}
						})
		},
	  	GetAllAddressForSamp(name,projectType,grouId,projectId){
			return axios.get(this.requestpath+'/api/Project/GetAllAddressForSamp',{
				params:{
					name:'',
					projectType:3,
					grouId:grouId,
					projectId:projectId
				},
				headers:{token:this.token}
			})
		},
		samplingInfoInit(){
			var _this = vueData
			
			var currentmon = JSON.parse(sessionStorage.getItem('monitems'))
			if(currentmon){
				if(currentmon.issence){
					_this.samplingObj.samplingsence = currentmon.data
				}else{
					_this.samplingObj.sampling = currentmon.data
				}
				_this.samplingObj.Mons = []
				_this.samplingObj.samplingsence.forEach(function(item){
					_this.samplingObj.Mons.push(item)
				})
				
				_this.samplingObj.sampling.forEach(function(item){
					_this.samplingObj.Mons.push(item)
				})
			}
		},
		GetMonsByTagId(tagId){
			return axios.get(this.requestpath+'/api/Project/GetMonsByTagId',{
						params:{
							tagId:tagId
						},
						headers:{token:this.token}
					})
		},
		SaveSamp(data){
			return axios({
					    method: 'post',
					    url: this.requestpath+'/api/Sampling/AddSampling',
					    data: {data:data},
					})
		},
		GetSamplingImg(SampId){
			return axios.post(this.requestpath+'/api/Sampling/CreateFileByImgByid',{id:SampId,fo:true},{headers:{token:this.token}})
		},
		GetDevicesByMothodIds(id){
			return axios.get(this.requestpath+'/api/Dev/GetDevicesByMothodIds',{
						params:{
							MothodIds:id
						},
						headers:{token:this.token}
					})
		},
		GetDeviceForLayGrid(page,rows){
			return axios.get(this.requestpath+'/api/Dev/GetDeviceForLayGrid',{
						params:{
							pageNumber:page,
							pageSize:rows
						},
						headers:{token:this.token}
					})
		},
		GetMonsByTagId(tagId){
			return axios.get(this.requestpath+'/api/Project/GetMonsByTagId',{
						params:{
							tagId:tagId
						},
						headers:{token:this.token}
					})
		}
		,
		initSele(){
			var _this = this
			var obj = vueData.currentmonSele
			_this.mons_sele = []
			obj.data.forEach(function(item,index){
				for(var i = 0;i<_this.mons_all.length;i++){
					if(item.MonitemName == _this.mons_all[i].Name){
						_this.mons_sele.push(_this.mons_all[i])
						continue
					}
				}
			})
			this.IsSence = obj.sence
			this.SampingCode = vueData.samplingObj.Row.SampingCode
		}
		,
		allsearch(value){
			var _this = this
			this.mons_all_search = []
			this.mons_all.forEach(function(item,index){
				if(item.Name.includes(value))
				{
					_this.mons_all_search.push(item)
				}
			})
		}
		,
		selesearch(val){
			
		},
		AddSele(item){
			var _this = this
			vueData.samplingObj.Mons.forEach(function(data,index){
				if(item.Id==data.MonitemId){
					vueData.samplingObj.Mons.splice(index,1)
					_this.SceneDataDel(data,!data.issense)
				}
			})
			var newsamp = {
				IsSence:this.IsSence,
				MonitemId:item.Id,
				MonitemName:item.Name,
				SampingCode:this.SampingCode
			}
			this.standDataAdd(newsamp,newsamp.IsSence)
			vueData.samplingObj.Mons.push(newsamp)
			this.SceneDataAdd(newsamp,newsamp.IsSence)
			vueData.sampDetail[vueData.samplingObjindex] = vueData.samplingObj
			service.sampdetailExt()
			service.loadmethod()
		},
		delSele(data){
			var _this = this
			vueData.samplingObj.Mons.forEach(function(item,index){
				if(data.Id==item.MonitemId){
					vueData.samplingObj.Mons.splice(index,1)
					_this.SceneDataDel(item,!item.issense)
				}
			})
			vueData.sampDetail[vueData.samplingObjindex] = vueData.samplingObj
			service.sampdetailExt()
		},
		standDataAdd(value,scene){
			if(scene){
				return
			}
			var isexitst = false
			vueData.sampDetail.forEach(function(item,index){
				item.Mons.forEach(function(data,num){
					if(data.MonitemName == value.MonitemName){
						isexitst = true
					}
				})
			})
			if(!isexitst){
				vueData.standData.push({
					StandNo:0,
					MonitemIds:value.MonitemId,
					MonitemName:value.MonitemName,
					SamplingAmount:"",
					AnalysisSite:"",
					SaveMehtod:"",
					Preservative:"",
					Count:"1",
					Container:"",
					SaveTimes:"",
					Index:"1",
					Id:this.getGuid(),
				})
			}
			
		},
		SceneDataAdd(item,scene){
			if(scene){
				var _this = this
				var isexists = false
				vueData.SceneData.forEach(function(data,index){
					if(item.MonitemName==data.Key){
						isexists = true
						data.q.push({
							SamplingId:"00000000-0000-0000-0000-000000000000",
							ProjectId:vueData.projectid,
							IsSenceAnalysis:true,
							SampStandId:_this.getGuid(),
							MonitemId:item.MonitemId,
							MonitemName:item.MonitemName,
							SampingCode:"",
							AddresssId:vueData.SampForm.AddressId,
							AddressName:vueData.SampForm.AddressName,
							OrderIndex:data.q.length+1+"",
							FrequecyNo:data.q.length+1+"",
							SamplingTime:"",
							SamplingType:0,
							SamplingCount:"0",
							Preservative:"否",
							IsCompare:false,
							SampleCollection:"",
							SampleAcceptance:"",
							Description:"",
							Value:"",
						 	ValueUnitNname:data.q[0].ValueUnitNname,
						 	ValueUnit1Name:data.q[0].ValueUnitNname,
						 	ValueUnit2Name:data.q[0].ValueUnitNname,
						 	ValueUnit3Name:data.q[0].ValueUnitNname,
						 	ValueUnit:data.q[0].ValueUnit,
						 	ValueUnit1:data.q[0].ValueUnit,
						 	ValueUnit2:data.q[0].ValueUnit,
						 	ValueUnit3:data.q[0].ValueUnit,
							MethodId:data.q[0].MethodId,
							DeviceId:"",
							MethodName:data.q[0].MethodName,
							DeviceIdName:"",
						})
					}
				})
				if(!isexists){
					vueData.SceneData.push({
						Key:item.MonitemName,
						q:[{
							SamplingId:"00000000-0000-0000-0000-000000000000",
							ProjectId:vueData.projectid,
							IsSenceAnalysis:true,
							SampStandId:_this.getGuid(),
							MonitemId:item.MonitemId,
							MonitemName:item.MonitemName,
							SampingCode:"",
							AddresssId:vueData.SampForm.AddressId,
							AddressName:vueData.SampForm.AddressName,
							OrderIndex:vueData.SceneData.length+1+"",
							FrequecyNo:vueData.SceneData.length+1+"",
							SamplingTime:"",
							SamplingType:0,
							SamplingCount:"0",
							Preservative:"否",
							IsCompare:false,
							SampleCollection:"",
							SampleAcceptance:"",
							Description:"",
							Value:"",
							ValueUnitNname:"",
							ValueUnit1Name:"",
							ValueUnit2Name:"",
							ValueUnit3Name:"",
							ValueUnit:"",
							ValueUnit1:"",
							ValueUnit2:"",
							ValueUnit3:"",
							MethodId:"",
							DeviceId:"",
							MethodName:"",
							DeviceIdName:"",
						}]
					})
				}
			}
		},
		SceneDataDel(item,scene){
			if(scene){
				var _this = this
				vueData.SceneData.forEach(function(data,index){
					if(item.MonitemName==data.Key){
						for(var i = 0;i<data.q.length;i++){
							if(data.q[i].SampingCode == _this.SampingCode){
								data.q.splice(i,1)
								if(data.q.length==0){
									vueData.SceneData.splice(index,1)
								}
							}
						}
					}
				})
			}
		},
		getGuid(){
		    var guid = "";
		    for (var i = 1; i <= 32; i++){
				var n = Math.floor(Math.random()*16.0).toString(16)
				guid+=n
				if(i==8||i==12||i==16||i==20){
					guid+="-"
				}
		    }
		    return guid;   
		},
		UploadFile(file){
			const data = new FormData();
			data.append('file', file.file);
			var res = axios.post('http://localhost:11450/api/Sampling/UploadFile2', data, {
			    headers: {
			        'Content-Type': 'multipart/form-data',
			    },
			});
			return  res;
		}
	},
	watch:{
		mons_all:function(){
			this.$nextTick(function(){
				this.isloading = false
				this.initSele()
			})
		}
	}
})

Vue.component("t-protable",{
	props:["pro","sampindex"],
	template:'<div class="rootnode" @click=""><div class="van-ellipsis">No.{{sampindex+1}}</div><div><div class="van-ellipsis">{{pro.Row.SampingCode||"待系统生成编号"}}<span style="margin-left: 40px;" class="van-ellipsis">{{pro.Row.SamplingTime}}</span></div><div class="van-ellipsis">监测：{{common.sampformat(pro.sampling)}}</span></div><div class="van-ellipsis">现场：{{common.sampformat(pro.samplingsence)}}</span></div></div></div>'
})

Vue.component('t-checkbox',{
	props:['Show','cbResult','cbSource','toggle','cbref'],
	template:'<van-popup  style="width: 100%;height: 50%;" v-model="Show" round position="bottom" ><van-checkbox-group v-model="cbResult"><van-cell-group><van-cell v-for="(item, index) in cbSource"  clickable :key="item" :title="`${item.Name}`" @click="toggle" ><template #right-icon><van-checkbox :name="item" ref="cbref" /></template></van-cell></van-cell-group></van-checkbox-group></van-popup>'
})

